//
//  XZ_RACloginVc.m
//  Project_Demo
//
//  Created by caoxiaozhu on 2018/7/27.
//  Copyright © 2018年 caoxiaozhu. All rights reserved.
//

#import "XZ_RACloginVc.h"
#import "XZ_LoginView.h"
#import "ViewModel.h"

@interface XZ_RACloginVc ()
@property(nonatomic,strong)ViewModel *viewModel;
@property(nonatomic,strong)NSString *changeLabelStr;

@end

@implementation XZ_RACloginVc

- (void)viewDidLoad {
    [super viewDidLoad];
    
    XZ_LoginView *loginView = [[[NSBundle mainBundle]loadNibNamed:@"XZ_LoginView" owner:self options:nil]firstObject];
    loginView.frame = self.view.bounds;
    [self.view addSubview:loginView];
    
    RAC(self.viewModel,loginName) = loginView.userNameField.rac_textSignal;
    RAC(self.viewModel,password) = loginView.passwordField.rac_textSignal;
    RAC(loginView.loginBtn,enabled) = self.viewModel.loginButtonEnableSignal;
    
    [[loginView.loginBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        [self.viewModel.loginCommad execute:nil];
    }];
    
    [self.viewModel.loginCommad.executionSignals.switchToLatest subscribeNext:^(id  _Nullable x) {
        NSLog(@"vc==x==>%@",x);
    }];
}

-(ViewModel *)viewModel{
    if (_viewModel == nil) {
        _viewModel = [[ViewModel alloc]init];
    }
    return _viewModel;
}

@end
